﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace XNA_Game_Framework
{
	internal class DrawArea
	{
		GraphicsDevice graphics;
		Viewport originalViewport;
		Viewport newViewport;

		public Viewport Get
		{
			get { return newViewport; }
		}

		public DrawArea(GraphicsDevice graphics, Rectangle drawArea)
		{
			this.graphics = graphics;

			originalViewport = graphics.Viewport;

			newViewport = originalViewport;

			newViewport.Width = drawArea.Width;
			newViewport.Height = drawArea.Height;
			newViewport.X = drawArea.X;
			newViewport.Y = drawArea.Y;

			if (newViewport.X < 0) 
			{newViewport.X = 0;}
			if (newViewport.Y < 0) 
			{newViewport.Y = 0; }

			if (newViewport.X > originalViewport.Width)
			{ newViewport.X = originalViewport.Width-10; }
			if (newViewport.Y > originalViewport.Height)
			{ newViewport.Y = originalViewport.Height-10; }

			if (newViewport.X + newViewport.Width > originalViewport.Width)
			{ newViewport.Width = originalViewport.Width - newViewport.X; }
			if (newViewport.Y + newViewport.Height > originalViewport.Height)
			{ newViewport.Height = originalViewport.Height - newViewport.Y; }

			graphics.Viewport = newViewport;
		}

		public void End()
		{
			graphics.Viewport = originalViewport;
		}
	}
}
